package com.yida.gwj.basis.controller.common;

import cn.hutool.core.bean.BeanUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.basis.domain.GwjOwnerAttest;
import com.yida.gwj.basis.domain.dto.GwjOwnerAttestDetailDTO;
import com.yida.gwj.basis.domain.dto.GwjOwnerAttestListDTO;
import com.yida.gwj.basis.domain.request.GwjOwnerAttestApproveRequest;
import com.yida.gwj.basis.domain.request.GwjOwnerAttestListRequest;
import com.yida.gwj.basis.enums.GwjOwnerAttestApproveStatus;
import com.yida.gwj.basis.service.IGwjOwnerAttestService;
import com.yida.gwj.common.utils.GwjConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lqq
 * @date 2023-08-25
 */
@RestController
@RequestMapping("/ownerAttest")
@Api(tags = "业主信息认证")
public class GwjOwnerAttestController extends BaseController {

    @Resource
    private IGwjOwnerAttestService gwjOwnerAttestService;

    @ApiOperation(value = "业主认证申请列表", response = GwjOwnerAttestListDTO.class)
    @GetMapping("/list")
    @RequiresPermissions("gwj:basis:ownerAttest:list")
    public TableDataInfo submit(GwjOwnerAttestListRequest request) {
        startPage();
        List<GwjOwnerAttest> list = gwjOwnerAttestService.selectGwjOwnerAttestList(BeanUtil.copyProperties(request, GwjOwnerAttest.class));
        return GwjConvertUtil.convertTable(getDataTable(list), GwjOwnerAttestListDTO.class);
    }

    @ApiOperation(value = "核对业主信息", response = GwjOwnerAttestDetailDTO.class)
    @GetMapping("/{ownerAttestId}")
    @RequiresPermissions("gwj:basis:ownerAttest:query")
    public AjaxResult getInfo(@PathVariable Long ownerAttestId) {
        return AjaxResult.success(BeanUtil.copyProperties(gwjOwnerAttestService.selectGwjOwnerAttestByOwnerAttestId(ownerAttestId), GwjOwnerAttestDetailDTO.class));
    }

    @Log(title = "业主信息认证-审批通过", businessType = BusinessType.UPDATE, systemName = "gwj")
    @PutMapping(value = "/pass")
    @ApiOperation(value = "业主信息认证-审批通过")
    @RequiresPermissions("gwj:basis:ownerAttest:approve")
    public AjaxResult pass(@RequestBody GwjOwnerAttestApproveRequest request) {
        request.setApproveCode(GwjOwnerAttestApproveStatus.PASS.getCode());
        gwjOwnerAttestService.approve(request);
        return AjaxResult.success("审批成功");
    }

    @Log(title = "业主信息认证-审批不通过", businessType = BusinessType.UPDATE, systemName = "gwj")
    @PutMapping(value = "/notPass")
    @ApiOperation(value = "审批不通过")
    @RequiresPermissions("gwj:basis:ownerAttest:approve")
    public AjaxResult notPass(@RequestBody GwjOwnerAttestApproveRequest request) {
        request.setApproveCode(GwjOwnerAttestApproveStatus.NOT_PASS.getCode());
        gwjOwnerAttestService.approve(request);
        return AjaxResult.success("审批成功");
    }
}
